<?php

if (!isset($_GET['type'])) {
 include "index.html";
 exit;
}

$type = ver('type');
$file = ver('file');

$path = "{$type}/{$file}{$type}.php";

if (is_file($path)) {
	include_once $path;
} else {
	exit("参数错误");
}

function dl($url) {

	$urlarr = explode("/", $url); 
	$domain = $urlarr[0];//分解出域名 
	$getfile = str_replace($urlarr[0], '', $url); 
	$content = @fsockopen("$domain", 80, $errno, $errstr, 12);//先连接上对方的服务器 

	if (!$content){
		die("对不起，无法连接上 $domain"); 
	} 
	fputs($content, "GET $getfile HTTP/1.0\r\n"); 
	fputs($content, "Host: $domain\r\n"); 
	fputs($content, "Referer: $domain\r\n");//伪造referfer 
	fputs($content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n\r\n"); 
	while (!feof($content)) { 
		$tp .= fgets($content, 128);
	} 
	$arr = explode("\n",$tp); 
	$arr1 = explode("Location: ",$tp); 
	$arr2 = explode("\n",$arr1[1]);
	header('Content-Type:application/force-download'); 
	header("location:".$arr2[0]); 
	fclose($content);

}

function ver($var, $nil = 1, $nuu = 2) {

	if ($nuu == 1) {
		if (!empty($_GET[$var])) {
			return $_GET[$var];
		} else {
			return '';
		}
	}
	
	if (!isset($_GET[$var])) {
		exit('参数不存在:' . $var);
	} else {
		if (!is_null($nil) and empty($_GET[$var])) {
			exit('参数不能为空:' . $var);
		} else {
			return $_GET[$var];
		}
	}
}

//统计
if(!file_exists("count.txt")){
        $one_file = fopen("count.txt","w+");
        fwrite("count.txt","1");  //把数字1写入文本
        fclose("$one_file");
}else{ 
        $num = file_get_contents("count.txt");
        $num++;
        file_put_contents("count.txt","$num");
        $newnum = file_get_contents("count.txt");
}
